import java.util.Scanner;
import java.util.Arrays;
public class Test{
    //拷贝数组
    public static void main(String[] args){
        int[] array2;
        array2 = new int[5];
        Arrays.copyOf(array2,1);
        System.out.print(Arrays.toString(array2));
    }
    //二维数组
    public static void main11(String[] args){
        int[][] array = {{1,2,3},{4,5,6}};
        for(int i = 0; i < array.length; i++){
            for(int j = 0; j < array[i].length; j++){
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
    //数组逆序
    public static void reverse(int[] array){
        int left = 0;
        int right = array.length - 1;
        while(left < right){
            int tmp = array[left];
            array[left] = array[right];
            array[right] = tmp;
            left++;
            right--;
        }
    }
    //冒泡排序
    public static void bubble(int[] array){
        int i = 0;
        for(i = 0; i < array.length - 1; i++){
            int j = 0;
            boolean falg = false;
            for(j = 0; j < array.length - 1 - i; j++){
                if(array[j] > array[j + 1]){//升序
                    int tmp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = tmp;
                    falg = true;
                }
            }
            if(falg == false){
                return;
            }
        }
    }
    public static void main10(String[] args){
        int[] array = {4,8,6,2,9,7,3,5,8,1};
       //bubble(array);
        reverse(array);
        System.out.println(Arrays.toString(array));
    }
    //二分查找
    public static int sreachNum(int[] array, int k){
        int left = 0;
        int right = array.length - 1;
        while(left <= right){
            int ave = (left + right) / 2;
            if(k < array[ave]){
                right = ave - 1;
            }
            else if(k > array[ave]){
                left = ave + 1;
            }
            else{
                return ave;//找到了
            }
        }
        return -1;//没找到
    }
    public static void main9(String[] args){
        int[] array = {1,2,3,4,5,6,7,8,9,10};
        Scanner scanner = new Scanner(System.in);
        int k = scanner.nextInt();
        int ret = sreachNum(array, k);
        if(ret != -1){
            System.out.println("找到了，下标是:" + ret);
        }
        else{
            System.out.println("没找到!");
        }
    }
    //模拟实现ToString(提高安全性)
    public static String myToSTring(int[] array){
        if(array == null){
            return null;
        }
        String str = "[";
        int i = 0;
        for(i = 0; i < array.length; i++){
            str += array[i];
            if(i != array.length - 1){
                str += ", ";
            }
        }
        str += "]";
        return str;
    }
    public static void main8(String[] args) {
        //模拟实现ToString
        int[] array = {1,2,3,4,5,6};
        String ret = myToSTring(array);
        System.out.println(ret);
    }
    public static void fun1(int[] array1){
        array1 = new int[]{4,5,6};
    }
    public static void fun2(int[] array2){
        array2[0] = 100;
    }
    public static void main7(String[] args){
        int[] array = {1,2,3};
        fun1(array);
        int i = 0;
        for(i = 0; i < array.length; i++){
            System.out.print(array[i] + " ");
        }
        System.out.println();
        fun2(array);
        for(i = 0; i < array.length; i++){
            System.out.print(array[i] + " ");
        }
    }
    //数组访问
    public static void main6(String[] args){
        int[] array = {1,2,3,4,5};
        //1
        int i = 0;
        for(i = 0; i < array.length; i++){
            System.out.print(array[i] + "   ");
        }
        System.out.println();
        //2
        for(int x : array){
            System.out.print(x + "   ");
        }
        System.out.println();
        //3
        String ret = Arrays.toString(array);
        System.out.println(ret);

    }
    //N的阶乘
    public static void main5(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int sum = 1;
        int i = 0;
        for(i = 1; i <= n; i++){
            sum *= i;
        }
        System.out.println(sum);
    }
    //在同一个类中定义多个方法：要求不仅可以求2个整数的最大值，还可以求3个小数的最大值？
    public static int maxNum(int x, int y){
        return (x > y ? x : y);
    }
    public static float maxNum(float x, float y, float z){
        if(x > y && x > z){
            return x;
        }
        else if(y > x && y > z){
            return y;
        }
        else{
            return z;
        }

    }
    public static void main4(String[] args){
        int max1 = maxNum(5,7);
        float max2 = maxNum(7.3f,2.5f,1.2f);
        System.out.println("最大值分别为:" + max1 + "," + max2);
    }
    //有一组数据，只有一个数字是出现一次，其他是两次，请找出这个数字
    public static void main3(String[] args){
        int[] array = { 1,2,3,2,1 };
        int sum = 0;
        int i = 0;
        for(i = 0; i < 5; i++){
            sum ^= array[i];
        }
        System.out.println(sum);
    }
    //阶乘
    public static int fac(int n){
        int sum = 1;
        while(n != 0){
            sum *= n;
            n--;
        }
        return sum;

    }

    public static void main2(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int sum = 0;
        int i = 0;
        for(i = n; i != 0; i--){
            sum += fac(i);
        }
        System.out.println(sum);
    }
    //在同一个类中,分别定义求两个整数的方法 和 三个小数之和的方法。 并执行代码，求出结果
    public static int addNum(int x,int y){
        return x + y;
    }
    public static float addNum(float x, float y, float z){
        return x + y + z;
    }
    public static void main1(String[] args){
        System.out.println(addNum(1,2));
        System.out.println(addNum(1.2f, 1.6f, 5.4f));
    }
}
